package com.example.chatrecommendation.tool;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author Jasmine-drs
 * @date 2024/5/22 17:04
 */

@Component
public class Neo4jCypherExecutor {

	private final Neo4jClient neo4jClient;

	@Autowired
	public Neo4jCypherExecutor(Neo4jClient neo4jClient) {
		this.neo4jClient = neo4jClient;
	}

	public List<Map<String, Object>> executeCypherQuery(String cypherQuery, Map<String, Object> parameters) {
		return (List<Map<String, Object>>) neo4jClient.query(cypherQuery)
				.bindAll(parameters)
				.fetch()
				.all();
	}

	public List<Map<String, Object>> executeCypherQuery(String cypherQuery) {
		return (List<Map<String, Object>>) neo4jClient.query(cypherQuery)
				.fetch()
				.all();
	}
}
